#pragma once
#include "imtPublic.h"
#include "imtGameScene.h"


namespace iMate {

	class IAttrib : public NormalAlloc
	{
	protected:
		String        mName;
		ISceneObject* mObject;
	public:
		IAttrib(const String& name, ISceneObject* obj) : mName(name), mObject(obj)
		{}
		virtual ~IAttrib(){}
		const String& getName(){return mName;}
		const ISceneObject* getObject() const {return (ISceneObject*)mObject;}

		virtual bool create(){return true;}
		virtual bool readOnly() const {return false;}

		virtual bool set(const String& strValue) {return true;}
		virtual String get() const =0;

		virtual const String& getType() const{return gNullName;}
		virtual const String& getShowType() const {return gNullName;}
	};

	class AttribSet : public NormalAlloc
	{
	protected:
		std::vector<IAttrib*> mAttribs;
		ISceneObject* mObject;
		AttribSet* mMoreAttribSet;
	public:
		AttribSet(ISceneObject* obj, AttribSet* more =0) 
			: mObject(obj), mMoreAttribSet(more)
		{}
		const ISceneObject* getObject() const {return (ISceneObject*)mObject;}
		void setMoreAttribSet(AttribSet* attribSet){mMoreAttribSet=attribSet;}

		virtual void getAttribs(std::vector<IAttrib*>& attribs);
		virtual IAttrib* getAttrib(const String& attribName);
		virtual void addAttrib(IAttrib* attrib);
		virtual void destroy();

	protected:
		IAttrib* findAttribInSelf(const String& attribName);
	};

	AttribSet* imtCreateAttribSet(ISceneObject* obj);

	class AttribSheet;

	class AttribSetShower : public NormalAlloc
	{
		AttribSet* mAttribSet;
		CEGUI::Window* mGuiShower;
		std::map<String, AttribSheet*> mAttribSheets;
	public:
		AttribSetShower() 
			: mAttribSet(0), mGuiShower(0)
		{}
		virtual ~AttribSetShower() 
		{}
		void bind(AttribSet* attribSet, CEGUI::Window* guiShower)
		{
			mAttribSet = attribSet; mGuiShower = guiShower;
			rebuildAttribSheets();
		}
		AttribSet* getAttribSet() const
		{return (AttribSet*)mAttribSet;}

		virtual void rebuildAttribSheets();
		virtual void update();
		virtual void update(const String& attribName);
		virtual void clearUi();
		virtual void clearData();
	};


}//iMate